Skip to main content

Registering Items

Info

warning

You should register all of your items in the inventory resource.

If you want you can create an export function for the RegisterItem function, but if the resource which is registering the new item starts slower, then the item will not be added to the inventory and may be deleted.

Arguments

---@field label string
---@field tradable boolean
---@field deletable boolean
---@field stackable boolean
---@field description string
---@field weight number
---@field category string
---@field defaultMeta InventoryItemMetaData
---@field usable boolean
---@field droppedModel string
---@field weaponHash number | string
---@field allowedAttachments string[]
---@field generateSerial boolean
---@field server? { export?: string; onUseDeleteAmount?:number; }

Example

Example
ScriptShared.Items:Add("money", {
stackable = true,
deletable = true,
tradable = true,
label = "Money",
weight = 0.0,
category = "Currency"
})

Use function example

Example
ScriptShared.Items:Add("gold", {
stackable = true,
deletable = true,
tradable = true,
label = "Gold",
weight = 1.5,
usable = true,
category = "Raw material",
server = {
export = "resource_name.any_function_name",
onUseDeleteAmount = 1
}
})

You should create the export function in the resource which was specified in the server.export variable.

Export function in the another resource
export("any_function_name", function(source, item)
print(source)
print(json.encode(item, { indent = true }))
end)